package com.orkasgb.framework.hadoop.mapperreduce.join.reducejoin;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class JoinReduce extends Reducer<Text, JoinEntity, NullWritable, JoinEntity> {
    private String name = "";

    @Override
    protected void reduce(Text key, Iterable<JoinEntity> values, Reducer<Text, JoinEntity, NullWritable, JoinEntity>.Context context) throws IOException, InterruptedException {
        for (JoinEntity join : values) {
            String flag = join.getflag();
            if (flag.equals("product")) {
                name = join.getName();
            } else {
                join.setName(name);
                context.write(NullWritable.get(), join);
            }
        }
    }
}
